package com.device.entity;

import javax.persistence.*;
import java.util.UUID;
import static com.device.util.StringUtils.isEquals;

@Entity
@Table(name = "polling_configs")
public class PollingConfig {
    
    @Id
    @Column(name = "id")
    private UUID id;
    
    @Column(name = "device_imei", nullable = false)
    private String deviceImei;
    
    @Column(name = "device_type", nullable = false)
    private String deviceType = "RS485";
    
    @Column(name = "response_timeout", nullable = false)
    private Integer responseTimeout = 500;
    
    @Column(name = "polling_interval", nullable = false)
    private Integer pollingInterval = 5000;
    
    @Column(name = "command_format", nullable = false)
    private String commandFormat = "HEX";
    
    @Column(name = "command1")
    private String command1 = "";
    
    @Column(name = "command2")
    private String command2 = "";
    
    @Column(name = "command3")
    private String command3 = "";
    
    @Column(name = "created_time")
    private Long createdTime;
    
    @Column(name = "updated_time")
    private Long updatedTime;
    
    // Constructors
    public PollingConfig() {}
    
    public PollingConfig(String deviceImei) {
        this.id = UUID.randomUUID();
        this.deviceImei = deviceImei;
        this.createdTime = System.currentTimeMillis();
        this.updatedTime = System.currentTimeMillis();
    }
    

    @Override
    public boolean equals(Object obj) {
        if(null == obj) return false;
        PollingConfig pollingConfig = (PollingConfig) obj;
        return isEquals(this.deviceImei, pollingConfig.getDeviceImei()) &&
                isEquals(this.deviceType, pollingConfig.getDeviceType()) &&
                this.responseTimeout.equals(pollingConfig.getResponseTimeout()) &&
                this.pollingInterval.equals(pollingConfig.getPollingInterval()) &&
                isEquals(this.commandFormat, pollingConfig.getCommandFormat()) &&
                isEquals(this.command1, pollingConfig.getCommand1()) &&
                isEquals(this.command2, pollingConfig.getCommand2()) &&
                isEquals(this.command3, pollingConfig.getCommand3());


    }
    
    // Getters and Setters
    public UUID getId() {
        return id;
    }
    
    public void setId(UUID id) {
        this.id = id;
    }
    
    public String getDeviceImei() {
        return deviceImei;
    }
    
    public void setDeviceImei(String deviceImei) {
        this.deviceImei = deviceImei;
    }
    
    public String getDeviceType() {
        return deviceType;
    }
    
    public void setDeviceType(String deviceType) {
        this.deviceType = deviceType;
    }
    
    public Integer getResponseTimeout() {
        return responseTimeout;
    }
    
    public void setResponseTimeout(Integer responseTimeout) {
        this.responseTimeout = responseTimeout;
    }
    
    public Integer getPollingInterval() {
        return pollingInterval;
    }
    
    public void setPollingInterval(Integer pollingInterval) {
        this.pollingInterval = pollingInterval;
    }
    
    public String getCommandFormat() {
        return commandFormat;
    }
    
    public void setCommandFormat(String commandFormat) {
        this.commandFormat = commandFormat;
    }
    
    public String getCommand1() {
        return command1;
    }
    
    public void setCommand1(String command1) {
        this.command1 = command1;
    }
    
    public String getCommand2() {
        return command2;
    }
    
    public void setCommand2(String command2) {
        this.command2 = command2;
    }
    
    public String getCommand3() {
        return command3;
    }
    
    public void setCommand3(String command3) {
        this.command3 = command3;
    }
    
    public Long getCreatedTime() {
        return createdTime;
    }
    
    public void setCreatedTime(Long createdTime) {
        this.createdTime = createdTime;
    }
    
    public Long getUpdatedTime() {
        return updatedTime;
    }
    
    public void setUpdatedTime(Long updatedTime) {
        this.updatedTime = updatedTime;
    }
} 